package com.etc;

import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestJDBC {

    public static void main(String[] args) {
        List<Map> list = new ArrayList<>();
        try (
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/lixiang", "root", "123456");
            PreparedStatement ps = conn.prepareStatement("select * FROM EMP");
        ) {
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                Map<String, Object> item = new HashMap<>();
                list.add(item);
                item.put("id", rs.getInt(1));
                item.put("ename", rs.getString("ename"));
                item.put("job", rs.getString("job"));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        list.forEach(item -> {
            item.forEach((k, v) -> System.out.print(k + "@" + v + "\t"));
            System.out.println();
        });
    }

}

